﻿using CarEdge.Infrastructure.Dto.Request.Consume;
using CarEdge.Infrastructure.Dto.Request.Customer;
using CarEdge.Infrastructure.Dto.Request.Dic;
using CarEdge.Service.Interface.Dic;
using CarEdge.Service.Interface;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using CarEdge.Infrastructure.Dto.Request.VIP;
using CarEdge.Service.Interface.VIP;

namespace CarEdge.Admin.Controllers.VIP;

    /// <summary>
    /// 会员管理
    /// </summary>
    [Authorize(Roles = "Admin")]

public class VIPController : BaseController
{


    private readonly I_VIP_Service _VIP_Service;
    private readonly IConfiguration _configuration;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="login_Service"></param>
    /// <param name="VIP_Service"></param>
    /// <param name="configuration"></param>
    public VIPController(I_Login_Service login_Service, I_VIP_Service VIP_Service, IConfiguration configuration) : base(login_Service)
    {
        _VIP_Service = VIP_Service;
        _configuration = configuration;
    }
    /// <summary>
    /// 获取所有会员
    /// </summary>
    /// <param name="status"></param>
    /// <param name="page"></param>
    /// <param name="limit"></param>
    /// <param name="key"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetAllVIP(int? page = 1, int? limit = 10, string? key = "", string? type = "")
    {
        var result = await _VIP_Service.GetAllVIP(page ?? 1, limit ?? 10, key ?? "", type ?? "");
        return Ok(result);
    }
    /// <summary>
    /// 恢复会员
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> hfvip(VIP_Request_Dto dto)
    {
        var result = await _VIP_Service.hfvip(dto);
        return Ok(result);
    }

    /// <summary>
    /// 获取消费次数
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> bindconsumption()
    {
        var result = await _VIP_Service.bindconsumption();
        return Ok(result);
    }
    /// <summary>
    /// 获取会员卡片
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> gethycard()
    {
        var result = await _VIP_Service.gethycard();
        return Ok(result);
    }
    /// <summary>
    /// 获取过期数据
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> getexpirehycard()
    {
        var result = await _VIP_Service.getexpirehycard();
        return Ok(result);
    }
    /// <summary>
    /// 获取最牛逼的会员
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> getbesthy()
    {
        var result = await _VIP_Service.getbesthy();
        return Ok(result);
    }
    /// <summary>
    /// 获取本周充值前五的
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> bindactiveEcharts()
    {
        var result = await _VIP_Service.bindactiveEcharts();
        return Ok(result);
    }
    [HttpGet]
    /// <summary>
    /// 获取最近添加
    /// </summary>
    /// <returns></returns>
    public async Task<IActionResult> getmincard()
    {
        var result = await _VIP_Service.getmincard();
        return Ok(result);
    }
    /// <summary>
    /// 绑定活跃会员
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> bindactive()
    {
        var result = await _VIP_Service.bindactive();
        return Ok(result);
    }
    /// <summary>
    /// 获取销售
    /// </summary>
    /// <param name="page"></param>
    /// <param name="limit"></param>
    /// <param name="key"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> BindSale()
    {
        var result = await _VIP_Service.BindSale();
        return Ok(result);
    }
    /// <summary>
    /// 获取会员数量
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> bindvipcount()
    {
        var result = await _VIP_Service.bindvipcount();
        return Ok(result);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="phone"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetName(string phone)
    {
        var result = await _VIP_Service.GetName(phone);
        return Ok(result);
    }
    /// <summary>
    /// 添加会员
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> AddVIP(VIP_Request_Dto dto)
    {
        var result = await _VIP_Service.AddVIP(dto);
        return Ok(result);
    }
    /// <summary>
    /// 获取所有会员类型
    /// </summary>
    /// <param name="page"></param>
    /// <param name="limit"></param>
    /// <param name="key"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetAllVIPType()
    {
        var result = await _VIP_Service.GetAllVIPType();
        return Ok(result);
    }

    /// <summary>
    /// 通过id获取会员类别详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetVIPTypeById(string id)
    {
        var result = await _VIP_Service.GetVIPTypeById(id);
        return Ok(result);
    }
    /// <summary>
    /// 获取单个vip
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetVIPById(string id)
    {
        var result = await _VIP_Service.GetVIPById(id);
        return Ok(result);
    }
    /// <summary>
    /// 充值
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> Recharge(Consume_Request_Dto dto)
    {
        var result = await _VIP_Service.Recharge(dto);
        return Ok(result);
    }
    /// <summary>
    /// 消费
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> Consumption(Consume_Request_Dto dto)
    {
        var result = await _VIP_Service.Consumption(dto);
        return Ok(result);
    }
    /// <summary>
    /// 通过会员id查询消费/充值记录
    /// </summary>
    /// <param name="id"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetVIPConsumeById(string id, int type)
    {

        var result = await _VIP_Service.GetVIPConsumeById(id, type);
        return Ok(result);
    }
    /// <summary>
    /// 删除会员
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> DeleteVIP(Customer_Request_Dto dto)
    {
        var result = await _VIP_Service.DeleteVIP(dto);
        return Ok(result);
    }

    /// <summary>
    /// 修改会员
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> UpdateVIP(VIP_Request_Dto dto)
    {
        var result = await _VIP_Service.UpdateVIP(dto);
        return Ok(result);
    }
    /// <summary>
    /// 获取最佳员工
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> bestuser()
    {
        var result = await _VIP_Service.bestuser();
        return Ok(result);
    }

    /// <summary>
    /// 今天充值情况
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> todayRecharge()
    {
        var result = await _VIP_Service.todayRecharge();
        return Ok(result);
    }
    /// <summary>
    /// 将会员过期
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> ExpireVIP(VIP_Request_Dto dto)
    {
        var result = await _VIP_Service.ExpireVIP(dto);
        return Ok(result);
    }
    /// <summary>
    /// 添加会员类型
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> AddVIPType(Dic_Request_Dto dto)
    {
        var user = await this.Get_Curr_User();
        dto.author = user.Uid;
        var result = await _VIP_Service.AddVIPType(dto);
        return Ok(result);
    }
    /// <summary>
    /// 删除会员类型
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> DeleteVIPType(VIP_Request_Dto dto)
    {
        var result = await _VIP_Service.DeleteVIPType(dto);
        return Ok(result);
    }

    /// <summary>
    /// 获取今/前年会员增加数量
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetLastYearVIPAdd()
    {
        var result = await _VIP_Service.GetLastYearVIPAdd();
        return Ok(result);
    }
    /// <summary>
    /// 获取今/前年会员充值金额
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetLastYearRecharge()
    {
        var result = await _VIP_Service.GetLastYearRecharge();
        return Ok(result);
    }

    /// <summary>
    /// 获取今日数据
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> BindTodayData()
    {
        var result = await _VIP_Service.BindTodayData();
        return Ok(result);
    }
    /// <summary>
    /// 获取会员充值/消费列表
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetUserRechargeByid(string id)
    {
        var result = await _VIP_Service.GetUserRechargeByid(id);
        return Ok(result);
    }
}

